package cn.z2huo.demo.spring.webmvc.controller;

import cn.z2huo.demo.spring.webmvc.vo.PostJsonNoRequestBodyAnnotationReqVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>各种类型的 Content-Type 请求的参数获取方式
 *
 * @author z2huo
 */
@Slf4j
@RestController
@RequestMapping("/contentTypeTest")
public class ContentTypeTestController {

    /**
     *
     * @param reqVO
     */
    @PostMapping("/postJsonNoRequestBodyAnnotation")
    public void postJsonNoRequestBodyAnnotation(PostJsonNoRequestBodyAnnotationReqVO reqVO) {
        log.info("TestController, /test/postJsonNoRequestBodyAnnotation, reqVO is {}", reqVO);
    }

    @GetMapping("/getNoneParam")
    public String getNoneParam() {
        log.info("TestController, /test/getNoneParam");
        return "success";
    }

    @GetMapping("/getHaveParam")
    public String getHaveParam(@RequestParam(value = "name", required = false) String name) {
        log.info("TestController, /test/getHaveParam");
        log.info("request Param, name is {}", name);
        return "success";
    }

    @GetMapping("/getHaveMapParam")
    public String getHaveMapParam(@RequestParam Map reqMap) {
        log.info("TestController, /test/getHaveMapParam");
        log.info("reqMap is {}", reqMap);
        log.info("request Param, name is {}", reqMap.get("name"));
        return "success";
    }

    @PostMapping("/postHaveParam")
    public String postHaveParam(@RequestParam(value = "name", required = false) String name) {
        log.info("TestController, /test/postHaveParam");
        log.info("request Param, name is {}", name);
        return "success";
    }

    @PostMapping("/postHaveMultiParam")
    public String postHaveMultiParam(@RequestParam(value = "name", required = false) String name,
                                    @RequestParam(value = "age", required = false) Integer age) {
        log.info("TestController, /test/postHaveMultiParam");
        log.info("request Param, name is {}, age is {}", name, age);
        return "success";
    }

    @PostMapping("/postHaveBodyParam")
    public String postHaveBodyParam(@RequestBody Map reqMap) {
        log.info("TestController, /test/postHaveBodyParam");
        log.info("request Param, name is {}", reqMap.get("name"));
        return "success";
    }

    @PostMapping("/postHaveMapParam")
    public String postHaveMapParam(@RequestParam Map reqMap) {
        log.info("TestController, /test/postHaveMapParam");
        log.info("reqMap is {}", reqMap);
        log.info("request Param, name is {}", reqMap.get("name"));
        return "success";
    }
}
